<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>执法对象属性设置管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		var maxVal=0;
		$(document).ready(function() {
			$("#btnExport").click(function(){
				top.$.jBox.confirm("确认要导出执法对象数据吗？","系统提示",function(v,h,f){
					if(v=="ok"){
						//$("#searchForm").attr("action","${ctx}/sys/user/export");
						$("#exportForm").submit();
					}
				},{buttonsFocus:1});
				top.$('.jbox-body .jbox-icon').css('top','55px');
			});			
			$("#btnImport").click(function(){
				$.jBox($("#importBox").html(), {title:"导入数据", buttons:{"关闭":true}, 
					bottomText:"导入文件不能超过5M，仅允许导入“xls”或“xlsx”格式文件！"});
			});
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});
		function addRow(list, idx, tpl, row){

			$(list).append(Mustache.render(tpl, {
				idx: idx, delBtn: true, row: row
			}));
			$(list+idx).find("select").each(function(){
				$(this).val($(this).attr("data-value"));
			});
			$(list+idx).find("input[type='checkbox'], input[type='radio']").each(function(){
				var ss = $(this).attr("data-value").split(',');
				for (var i=0; i<ss.length; i++){
					if($(this).val() == ss[i]){
						$(this).attr("checked","checked");
					}
				}
			});
			//alert(maxVal);
			//alert($(list).length);
			
			$(".digits").each(function(index){
				if($(this).val()==null||$(this).val()==''){ 
					//maxVal++;
					$(this).val(++maxVal);
				}
				//alert(index+"-"+$(this).val());
				if($(this).val()>maxVal){ 
					maxVal = $(this).val();
				}
		  	});			
		}
		function delRow(obj, prefix){
			var id = $(prefix+"_id");
			var delFlag = $(prefix+"_delFlag");
			if (id.val() == ""){
				$(obj).parent().parent().remove();
			}else if(delFlag.val() == "0"){
				delFlag.val("1");
				$(obj).html("&divide;").attr("title", "撤销删除");
				$(obj).parent().parent().addClass("error");
			}else if(delFlag.val() == "1"){
				delFlag.val("0");
				$(obj).html("&times;").attr("title", "删除");
				$(obj).parent().parent().removeClass("error");
			}
		}		
	</script>
</head>
<body>
	<div id="importBox" class="hide">
		<form id="importForm" action="${ctx}/zfdxktitle/drZfdxkTitle/import" method="post" enctype="multipart/form-data"
			class="form-search" style="padding-left:20px;text-align:center;" onSubmit="loading('正在导入，请稍等...');"><br/>
			<input id="uploadFile" name="file" type="file" style="width:330px"/><br/><br/>
            <input type="checkbox" name="delf" id="delf" value="1" style="margin-left:-160px"/>是否删除已有执法对象　　
            <br/><br/>
			<input id="btnImportSubmit" class="btn btn-primary" type="submit" value="   导    入   "/>
            <input type="hidden" name="sx_id" value="${drSx.id}" id="sx_id"/>
		</form>
	</div>
	<ul class="nav nav-tabs">
		<li class="active"><a href="">执法对象属性维护</a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="drSx" action="${ctx}/zfdxktitle/drZfdxkTitle/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>	
            <div class="control-group">
                <label class="control-label">事项名称：</label>
                <div class="controls">
                    ${drSx.sxMc}
                </div>
            </div>        
			<div class="control-group">
				<label class="control-label">属性名称设置：</label>
				<div class="controls">
					<table id="contentTable" class="table table-striped table-bordered table-condensed">
						<thead>
							<tr>
								<th class="hide"></th>
								<th>序号</th>
								<th>属性名称</th>
                                
								<shiro:hasPermission name="zfdxktitle:drZfdxkTitle:edit"><th width="10">&nbsp;</th></shiro:hasPermission>
							</tr>
						</thead>
						<tbody id="drZfdxkTitleList">
						</tbody>
						<shiro:hasPermission name="zfdxktitle:drZfdxkTitle:edit"><tfoot>
							<tr><td colspan="11"><a href="javascript:" onClick="addRow('#drZfdxkTitleList', drZfdxkTitleRowIdx, drZfdxkTitleTpl);drZfdxkTitleRowIdx = drZfdxkTitleRowIdx + 1;" class="btn">新增</a></td></tr>
						</tfoot></shiro:hasPermission>
					</table>
					<script type="text/template" id="drZfdxkTitleTpl">//<!--
						<tr id="drZfdxkTitleList{{idx}}">
							<td class="hide">
								<input id="drZfdxkTitleList{{idx}}_id" name="drZfdxkTitleList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
								<input id="drZfdxkTitleList{{idx}}_delFlag" name="drZfdxkTitleList[{{idx}}].delFlag" type="hidden" value="0"/>
							</td>
							<td>
								<input id="drZfdxkTitleList{{idx}}_dxTXh" name="drZfdxkTitleList[{{idx}}].dxTXh" type="text" value="{{row.dxTXh}}" maxlength="2" class="input-xlarge digits"/>
							</td>
							<td>
								<input id="drZfdxkTitleList{{idx}}_dxTMc" name="drZfdxkTitleList[{{idx}}].dxTMc" type="text" value="{{row.dxTMc}}" maxlength="255" class="input-xlarge "/>
							</td>
							<shiro:hasPermission name="zfdxktitle:drZfdxkTitle:edit"><td class="text-center" width="10">
								{{#delBtn}}<span class="close" onclick="delRow(this, '#drZfdxkTitleList{{idx}}')" title="删除">&times;</span>{{/delBtn}}
							</td></shiro:hasPermission>
						</tr>//-->
					</script>
					<script type="text/javascript">
						var drZfdxkTitleRowIdx = 0, drZfdxkTitleTpl = $("#drZfdxkTitleTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
						$(document).ready(function() {
							var data = ${fns:toJson(drSx.drZfdxkTitleList)};
							for (var i=0; i<data.length; i++){
								addRow('#drZfdxkTitleList', drZfdxkTitleRowIdx, drZfdxkTitleTpl, data[i]);
								drZfdxkTitleRowIdx = drZfdxkTitleRowIdx + 1;
							}
						});
					</script>
				</div>
			</div>        	
		<div class="form-actions">
        	<shiro:hasPermission name="zfdxktitle:drZfdxkTitle:edit"><input id="btnExport" class="btn btn-primary" type="button" value="导出Excel" style="margin-bottom:10px"/><br/></shiro:hasPermission>
        	<shiro:hasPermission name="zfdxktitle:drZfdxkTitle:edit"><input id="btnImport" class="btn btn-primary" type="button" value="导入Excel" style="margin-bottom:10px"/><span class="help-inline" style="margin-bottom:10px"> 将表头和执法对象数据一并导入，默认第一行为表头。</span><br/></shiro:hasPermission>
			<shiro:hasPermission name="zfdxktitle:drZfdxkTitle:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="下一步，添加执法对象"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onClick="history.go(-1)"/>
		</div>
	</form:form>
		<form id="exportForm" action="${ctx}/zfdxktitle/drZfdxkTitle/export" method="post" enctype="multipart/form-data"
			class="form-search" style="padding-left:20px;text-align:center;"><br/>
            <input type="hidden" name="sx_id" value="${drSx.id}" id="sx_id"/>
		</form>    
</body>
</html>